<%@ page import="bean.Person" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/1
  Time: 10:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>el01</title>
</head>
<body>
<%--从web域中获取信息：page、request、session、application--%>
<%--等价于：pageContext.findAttribute("");--%>
<%
//    设置属性user
    pageContext.setAttribute("user","张三");
%>
<%--1、获取普通的属性信息--%>
<p>${user}</p>
<%--2、通过el获取JavaBean的属性信息--%>
<%
    Person person = new Person();
    person.setPersonName("中国人");
    pageContext.setAttribute("person1",person);
%>
<p>${person1}------${person1.personName}</p>

<%--3、el表达式获取数组信息--%>
<%
//    定义数组且赋值
    String[] name={"东哥","大聪明","大个"};
    String[] name2=new String[3];
    name2[0]="东哥";
    name2[1]="大聪明";
    name2[2]="大个";
    pageContext.setAttribute("names",name);
%>
<p>${names}</p>
<p>${names[0]}----${names[1]}------${names[2]}</p>
<%--4、el表达式获取集合collection信息--%>
<%
    List<String> nameList = new ArrayList<>();
    nameList.add("张三1");
    nameList.add("张三2");
    nameList.add("张三3");
    request.setAttribute("lists",nameList);
%>
<p>${lists}</p>
<p>${lists[0]}----${lists[1]}-----${lists[2]}</p>
<%--5、el表达式获取map集合信息--%>
<%
    Map<String,Object> maps = new HashMap<>();
    maps.put("chinese",80);
    maps.put("math","98");
    maps.put("english",90.5);

    session.setAttribute("score",maps);
%>
<p>${score}</p>
<p>${score.chinese}----${score.math}-----${score.english}</p>
<p>${score["chinese"]}----${score["math"]}---${score["english"]}</p>

<%
    Person p1 = new Person();
    p1.setPersonName("壮壮");
    p1.setPersonAge(1);

    Person p2 = new Person();
    p2.setPersonName("大壮");

    List<Person> list = new ArrayList<>();
    list.add(p1);
    list.add(p2);
    session.setAttribute("personList",list);
//    el获取动态值
    int i=0;
    session.setAttribute("i",i);

%>
<p>${personList}</p>
<p>${personList[0].personName}</p>
<p>${personList[1].personName}</p>
<p>${personList[i].personName}</p>


<%
    List<Map<String,Object>> list2 = new ArrayList<>();

    Map<String,Object> map1 = new HashMap<>();
    map1.put("p","屁");

    Map<String,Object> map2 = new HashMap<>();
    map2.put("p1",p1);
    map2.put("p2","张三");
    map2.put("p3",10);
    map2.put("p4",list);
    map2.put("p5",map1);

    list2.add(map2);
    request.setAttribute("li",list2);
%>
<p>${li[0]}</p>
<p>${li[0].p1.personName}----${li[0].p2}</p>


</body>
</html>
